package com.app.aipass.view;

import com.app.aipass.R;
import com.app.aipass.entity.MyPacketEntity;
import com.app.aipass.utils.NumberUtils;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class MyPacketAdapter extends BaseMultiItemQuickAdapter<MyPacketEntity.DataDTO, BaseViewHolder> {


    public MyPacketAdapter(List<MyPacketEntity.DataDTO> data) {
        super(data);
        addItemType(1, R.layout.item_my_packet);
        addItemType(2, R.layout.item_my_packet_three);
        addItemType(3, R.layout.item_my_packet_two);
    }

    @Override
    protected void convert(BaseViewHolder holder, MyPacketEntity.DataDTO productBean) {
        switch (productBean.getP_id()){
            case 1:
                holder.setText(R.id.tvLevel,"1级");
                if (holder.getItemViewType()==1){
                    holder.setImageResource(R.id.ivBox,R.mipmap.icon_qyb_box_one);
                }else {
                    holder.setImageResource(R.id.ivBox,R.mipmap.icon_qyb_box_one_over);
                }
                break;
            case 2:
                holder.setText(R.id.tvLevel,"2级");
                if (holder.getItemViewType()==1){
                    holder.setImageResource(R.id.ivBox,R.mipmap.icon_qyb_box_two);
                }else {
                    holder.setImageResource(R.id.ivBox,R.mipmap.icon_qyb_box_two_over);
                }
                break;
            case 3:
                holder.setText(R.id.tvLevel,"3级");
                if (holder.getItemViewType()==1){
                    holder.setImageResource(R.id.ivBox,R.mipmap.icon_qyb_box_three);
                }else {
                    holder.setImageResource(R.id.ivBox,R.mipmap.icon_qyb_box_three_over);
                }
                break;
            case 4:
                holder.setText(R.id.tvLevel,"4级");
                if (holder.getItemViewType()==1){
                    holder.setImageResource(R.id.ivBox,R.mipmap.icon_qyb_box_four);
                }else {
                    holder.setImageResource(R.id.ivBox,R.mipmap.icon_qyb_box_four_over);
                }
                break;
            case 5:
                holder.setText(R.id.tvLevel,"5级");
                if (holder.getItemViewType()==1){
                    holder.setImageResource(R.id.ivBox,R.mipmap.icon_qyb_box_five);
                }else {
                    holder.setImageResource(R.id.ivBox,R.mipmap.icon_qyb_box_five_over);
                }
                break;
        }

        if (holder.getItemViewType()==1){
            holder.addOnClickListener(R.id.ivDelete);
        }
        holder.setText(R.id.tvDayNum, Double.parseDouble(productBean.getDays_ratio()) + "");
        holder.setText(R.id.tvAlreadyNum, NumberUtils.keepPrecision(productBean.getAcc_income(),2));
        holder.setText(R.id.tvTime, productBean.getReceive_days() + "/" + productBean.getLease_days());
    }
}
